package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.AddSellService;
import com.atguigu.spzx.model.dto.sell.sellDto;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.atguigu.spzx.model.vo.sell.SellVo;
import com.atguigu.spzx.utils.AuthContextUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.atguigu.spzx.model.dto.sell.sellDto;


@Tag(name = "售卖闲置接口")
@RestController
@RequestMapping(value = "/admin")
public class AddSellProduceController {
    @Autowired
    private AddSellService addSellService;

    //添加闲置
    @PostMapping("/addsellunused")
    public Result<sellDto> Addsell(@RequestBody sellDto sellDto){
        addSellService.Addsell(sellDto);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    //获取个人商品
    @GetMapping("/addsellunused/findByPage/{pageNum}/{pageSize}")
    public Result<PageInfo<SellVo>> GetSellListByPage(@PathVariable Integer pageNum, @PathVariable Integer pageSize){
        PageInfo<SellVo> pageInfo = addSellService.findByPage(pageNum,pageSize);
        return Result.build(pageInfo,ResultCodeEnum.SUCCESS);
    }

    //下架商品
    @DeleteMapping("/addsellunused/shelfProduct/{id}")
    public Result shelfProduct(@PathVariable Integer id){
        addSellService.DeleteSell(id);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    //修改商品
    @PutMapping("/addsellunused/updateProduct")
    public Result updateProduct(@RequestBody sellDto sellDto){
        addSellService.UpdateProduct(sellDto);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
}
